import Mock from 'mockjs';

const userData = [{
    username: 'aaa',
    password: '123'
  },
  {
    username: 'bbb',
    password: '456'
  }
]
Mock.mock('/api/list', Mock.mock({
  'list|1000': [{
    id: "@id",
    name: "@ctitle",
    "type|1": ["鸡翅", "汉堡", "可乐", "套餐"],
    image: "@image(100X100,@color,@city)"
  }]
}))

Mock.mock('/api/login', 'post', function (option) {
  let {
    username,
    password
  } = JSON.parse(option.body);
  console.log('option.body', option.body);
  let flag = userData.some((item) => {
    console.log('username', username);
    console.log('item.username', item.username);
    console.log('password', password);
    console.log('item.password', item.password);
    return username + '' === item.username + '' && password + '' === item.password + '';
  });


  if (flag) {
    return {
      success: 1,
      message: '用户登录成功',
      token: new Date().getTime() + username
    }
  } else {
    return {
      success: 0,
      message: '用户名或者密码错误'
    }
  }
});